package cn.kgc.javaweb.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: mosin
 * @version: v1.0  2022/5/24
 */
@WebServlet("/register")
public class RegisterServlet extends HttpServlet {

    // 分析HttpServletRequest 可以获取的参数
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取请求方式
        String method = req.getMethod();
        System.out.println("method = " + method);
        //获取项目的虚拟路径
        String contextPath = req.getContextPath();
        System.out.println("contextPath = " + contextPath);
        //请求路径  /register
        String servletPath = req.getServletPath();
        System.out.println("servletPath = " + servletPath);
        //http://localhost:8080/javaweb/register   全路径
        StringBuffer requestURL = req.getRequestURL();
        System.out.println("requestURL = " + requestURL);
        //  /javaweb/register  资源路径
        String requestURI = req.getRequestURI();
        System.out.println("requestURI = " + requestURI);
    }
}
